<template>
  <div v-loading="loading">
    <div class="header-search cad-box">
      <el-input
        v-model="searchValue.title"
        style="width: 20%"
        clearable
        placeholder="请输入标题"
      />
      <el-select
        v-model="searchValue.type"
        placeholder="请选择类型"
        style="width: 20%; margin: 0px 10px"
        clearable
      >
        <el-option
          v-for="item in options1"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
      <el-select
        v-model="searchValue.classify"
        placeholder="请选择分类"
        style="width: 20%"
        clearable
      >
        <el-option
          v-for="item in options2"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
      <el-button
        type="primary"
        style="margin: 0px 10px"
        @click="handleInformationDeliveryList"
      >搜索</el-button>
    </div>

    <div class="content-table cad-box">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column label="序号" type="index" align="center" />
        <el-table-column prop="type" label="类型" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.type === 1">长沙卫健委</div>
            <div v-if="scope.row.type === 2">国家卫健委</div>
          </template>
        </el-table-column>
        <el-table-column prop="classify" label="分类" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.classify === 1">法律</div>
            <div v-if="scope.row.classify === 2">政策</div>
            <div v-if="scope.row.classify === 3">标准</div>
            <div v-if="scope.row.classify === 4">通知</div>
          </template>
        </el-table-column>
        <el-table-column prop="title" label="标题" align="center" />
        <el-table-column prop="createTime" label="创建时间" align="center" />
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="handleInfo(scope.row)"
            >详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div style="text-align: right">
        <el-pagination
          :current-page="pagination.pageNum"
          :page-sizes="[10, 15, 30, 50]"
          :page-size="pagination.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

    <el-drawer title="详情" :visible.sync="drawer" :direction="direction">
      <div class="drawer_box">
        <div class="drawer_item">标题：{{ infoItem.title }}</div>
        <div class="drawer_item" style="justify-content: space-between">
          <div>
            类型：
            <span v-if="infoItem.type === 1">长沙卫健委</span>
            <span v-if="infoItem.type === 2">国家卫健委</span>
          </div>
          <div style="margin-left: 50px">
            分类：
            <span v-if="infoItem.classify === 1">法律</span>
            <span v-if="infoItem.classify === 2">政策</span>
            <span v-if="infoItem.classify === 3">标准</span>
            <span v-if="infoItem.classify === 4">通知</span>
          </div>
        </div>
        <div class="drawer_item" style="word-break: break-word">
          <span style="display: block; width: 140px">备注：</span><span v-html="infoItem.content" />
        </div>
        <div class="drawer_item" style="display: block">
          文件：
          <div
            v-for="(item, index) in infoItem.file"
            :key="index"
            style="margin: 10px"
          >
            <a
              :href="item.url"
              target="_blank"
              style="
                width: 100%;
                display: block;
                white-space: normal;
                word-wrap: break-word;
              "
            >{{ item.url }}</a>
          </div>
        </div>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import { informationDeliveryList } from './api/index'
export default {
  data () {
    return {
      options1: [
        {
          value: 1,
          label: '长沙卫健委'
        },
        {
          value: 2,
          label: '国家卫健委'
        }
      ],
      options2: [
        {
          value: 1,
          label: '法律'
        },
        {
          value: 2,
          label: '政策'
        },
        {
          value: 3,
          label: '标题'
        },
        {
          value: 4,
          label: '通知'
        }
      ],
      value1: '',
      value2: '',
      drawer: false,
      direction: 'rtl',
      infoItem: {},
      loading: false,
      searchValue: {
        title: '',
        classify: '',
        type: ''
      },
      tableData: [],
      pagination: {
        pageNum: 1,
        pageSize: 10
      },
      total: 0
    }
  },
  computed: {},
  created () {
    this.handleInformationDeliveryList()
  },
  mounted () {},
  methods: {
    async handleInformationDeliveryList () {
      const { records, total } = await informationDeliveryList({
        pageNum: this.pagination.pageNum,
        pageSize: this.pagination.pageSize,
        title: this.searchValue.title,
        type: this.searchValue.type,
        classify: this.searchValue.classify
      })
      this.tableData = records
      this.total = Number(total)
    },
    handleInfo (item) {
      this.drawer = true
      this.infoItem = item
      console.log(this.infoItem.file, 'handleInfo')
      this.infoItem.file = JSON.parse(this.infoItem.file)
      console.log(this.infoItem, 'handleInfo')
    },
    onSubmit () {},
    getTableList () {},
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`)
      this.pagination.pageSize = val
      this.handleInformationDeliveryList()
    },

    handleCurrentChange (val) {
      console.log(`当前页: ${val}`)
      this.pagination.pageNum = val
      this.handleInformationDeliveryList()
    }
  }
}
</script>

<style scoped lang="scss">
::v-deep .el-drawer__open .el-drawer.rtl {
  width: 66% !important;
  overflow-y: auto !important;
  overflow-x: auto !important;
}
/* 移除下划线 */
a {
  text-decoration: none;
}

/* 改变未访问链接的颜色 */
a:link {
  color: skyblue;
}

/* 改变已访问链接的颜色 */
a:visited {
  color: purple;
}

/* 当鼠标悬停在链接上时改变颜色 */
a:hover {
  color: orange;
  text-decoration: underline;
}

/* 鼠标点击时的状态 */
a:active {
  color: red;
}
::v-deep .el-drawer__header {
  color: #000 !important;
  font-size: 18px !important;
}

.header-search {
  display: flex;
  margin-bottom: 30px;

  .select-box {
    width: 20%;
    margin: 0 20px;
  }
}

.drawer_box {
  width: 100%;
  padding: 0px 50px;
  .drawer_item {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 20px;
    padding: 10px;
  }
}
</style>
